// login.aspx.cs created with MonoDevelop
// User: david at 10:22 PM 8/13/2008
//
//

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

namespace VolunteerTracker
{
	
	
	public partial class login : System.Web.UI.Page
	{
		
		/// <summary>
		/// When user attempts to login, this event will fire.  It connects to the database
		/// and determines if the user credentials are valid.
		/// </summary>
		protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
		{
			try
			{
				MySqlConnection con = dbConnect.GetConnection();
				con.Open();
				string select = "select * from users where email = ?email and password = ?password;";
				MySqlParameter email = new MySqlParameter("?email", MySqlDbType.VarChar);
				email.Value = login1.UserName;
				MySqlParameter password = new MySqlParameter("?password", MySqlDbType.VarChar);
				password.Value = login1.Password;
				MySqlCommand com = new MySqlCommand(select, con);
				com.Parameters.Add(email);
				com.Parameters.Add(password);
				MySqlDataReader dr = com.ExecuteReader();
				
				//If it returns anything we know it was successful
				if(dr.HasRows)
				{
					e.Authenticated = true;
				}
				
			}
			catch(Exception ex)
			{
				Response.Write("Error connecting");
#if DEBUG
				Response.Write(ex.ToString());
#endif
			}
		}
	}
}
